package com.wc.alorithm_luogu.P4387;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Stack;

/**
 * @Author congge
 * @Date 2023/5/21 12:16
 * @description
 */
public class Main2 {
    public static void main(String[] args) {
        Input sc = new Input();
        int q = sc.nextInt();

        while (q-- > 0) {
            int n = sc.nextInt();

            int[] pushElement = new int[n];
            int[] pollElement = new int[n];

            for (int i = 0; i < n; i++) {
                pushElement[i] = sc.nextInt();
            }

            for (int i = 0; i < n; i++) {
                pollElement[i] = sc.nextInt();
            }

            Stack<Integer> stack = new Stack<>();

            int pushIndex = 0;
            for (int i = 0; i < n; i++) {
                stack.push(pushElement[i]);

                while (stack.peek() == pollElement[pushIndex]) {
                    stack.pop();
                    pushIndex++;
                    if (stack.isEmpty()) {
                        break;
                    }
                }
            }

            if (stack.isEmpty()) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }


    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (int) in.nval;
        }
    }
}
